<template>
  <div class="mod-config">
    <el-form
      :inline="true"
      :model="queryInfo"
      @keyup.enter.native="getDataList()"
    >
      <el-form-item>
        <el-input
          v-model="queryInfo.example.operationMode"
          :placeholder="i18n['log.sys.field.operationMode.title']"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{
          i18n["gobal.button.search"]
        }}</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%"
    >
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50"
      >
      </el-table-column>
      <el-table-column
        prop="logId"
        header-align="center"
        align="center"
        width="100"
        :label="i18n['log.sys.field.logId.title']"
      >
      </el-table-column>
      <el-table-column
        prop="logTime"
        header-align="center"
        align="center"
        width="200"
        :formatter="datetimeFormat"
        :label="i18n['log.sys.field.logTime.title']"
      >
      </el-table-column>
      <el-table-column
        prop="userType"
        header-align="center"
        align="center"
        width="100"
        :formatter="userTypeFormat"
        :label="i18n['log.sys.field.userType.title']"
      >
      </el-table-column>
      <el-table-column
        prop="userId"
        header-align="center"
        align="center"
        width="160"
        :label="i18n['log.sys.field.userId.title']"
      >
      </el-table-column>
      <el-table-column
        prop="operationMode"
        header-align="center"
        align="center"
        width="100"
        :label="i18n['log.sys.field.operationMode.title']"
      >
      </el-table-column>
      <el-table-column
        prop="operation"
        header-align="center"
        align="center"
        :label="i18n['log.sys.field.operation.title']"
      >
      </el-table-column>
      <el-table-column
        prop="method"
        header-align="center"
        align="center"
        v-if="false"
        :label="i18n['log.sys.field.method.title']"
      >
      </el-table-column>
      <el-table-column
        prop="params"
        header-align="center"
        align="center"
        v-if="false"
        :label="i18n['log.sys.field.params.title']"
      >
      </el-table-column>
      <el-table-column
        prop="consumeMs"
        header-align="center"
        align="center"
        width="120"
        :label="i18n['log.sys.field.consumeMs.title']"
      >
      </el-table-column>
      <el-table-column
        prop="originateIp"
        header-align="center"
        align="center"
        width="120"
        :label="i18n['log.sys.field.originateIp.title']"
      >
      </el-table-column>
      <el-table-column
        prop="originateModule"
        header-align="center"
        align="center"
        width="120"
        :label="i18n['log.sys.field.originateModule.title']"
      >
      </el-table-column>
      <el-table-column
        prop="originateApp"
        header-align="center"
        align="center"
        width="120"
        :label="i18n['log.sys.field.originateApp.title']"
      >
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        :label="i18n['gobal.tips.operation']"
      >
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="small"
            @click="showDetailHandle(scope.row)"
            >{{ i18n["log.sys.button.details"] }}</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="queryInfo.page.pageNo"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="queryInfo.page.pageSize"
      :total="queryInfo.page.dataCount"
      layout="total, sizes, prev, pager, next, jumper"
    >
    </el-pagination>
    <!-- 弹窗, 显示方法和参数 -->
    <show-detail v-if="showDetailVisible" ref="showDetail"></show-detail>
  </div>
</template>

<script>
import { datetimeFormat, userTypeFormat } from "../../common/common";
import ShowDetail from "./sys-show-detail";
export default {
  inject: ["i18n"],
  data() {
    return {
      queryInfo: {
        key: "",
        example: {},
        page: {
          pageNo: 1,
          pageSize: 20,
          dataCount: null,
        },
      },
      dataList: [],
      dataListLoading: false,
      dataListSelections: [],
      showDetailVisible: false,
    };
  },
  components: {
    ShowDetail,
  },
  activated() {
    this.getDataList();
  },
  methods: {
    datetimeFormat,
    userTypeFormat,
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      this.$http({
        url: this.$http.adornUrl("/log/sys/list"),
        method: "post",
        data: this.$http.adornData({
          page: this.queryInfo.page,
          example: this.queryInfo.example,
        }),
      }).then(({ data }) => {
        if (data && data.code === 200 && data.data && data.data.list) {
          this.dataList = data.data.list;
          this.queryInfo.page.dataCount = Number(data.data.page.dataCount);
        } else {
          this.dataList = [];
          this.queryInfo.page.dataCount = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.queryInfo.page.pageSize = val;
      this.queryInfo.page.pageNo = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.queryInfo.page.pageNo = val;
      this.getDataList();
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val;
    },
    // 新增 / 修改
    showDetailHandle(row) {
      this.showDetailVisible = true;
      this.$nextTick(() => {
        this.$refs.showDetail.init(row);
      });
    },
  },
};
</script>
